"""主页"""
from time import sleep

from selenium.webdriver.common.by import By


from page.base_page import BasePage


class HomePage(BasePage):
    url="/index.php?m=dynamic&a=index"
    customer_locator = (By.LINK_TEXT, "客户")
    clue_locator = (By.LINK_TEXT, "线索")
    product_locator = (By.LINK_TEXT, "产品")
    agreement_locator = (By.LINK_TEXT, "合同")
    nav_right_locator = (By.CLASS_NAME, "pull-right")
    dropdown_open_locator = (By.CSS_SELECTOR,"body > div.navbar.navbar-inverse.navbar-fixed-top > div > div > div.nav-collapse.collapse > ul.nav.pull-right > li:nth-child(6) > a > img")
    system_settings_locator = (By.LINK_TEXT, "系统设置")
    business_locator = (By.LINK_TEXT, "商机")
    click_finance_locator = (By.LINK_TEXT, "财务")
    click_task_locator = (By.LINK_TEXT, "任务")
    tips_success_locator = (By.CSS_SELECTOR, "body > div.container > div.alert.alert-success")
    click_knowledge_locator = (By.LINK_TEXT, "知识")
    click_log_locator = (By.LINK_TEXT, "日志")
    click_in_site_message_locator = (By.LINK_TEXT, "站内信")
    def tips_success_text(self):
        text = self.find_element(self.tips_success_locator).text
        return text
    def click_finance(self):
        """点击财务"""
        self.click(self.click_finance_locator)
    def my_task_name(self):
        """点击任务"""
        self.click(self.click_task_locator)
    def click_customer(self):
        #进入客户#
        self.find_element(self.customer_locator).click()
    def click_clue(self):
        #进入线索#
        self.find_element(self.clue_locator).click()
    def click_product(self):
        #进入产品#
        self.find_element(self.product_locator).click()
    def click_agreement(self):
        #进入合同#
        self.find_element(self.agreement_locator).click()
    def click_system_settings(self):
        # 定位右边导航#
        nav_right = self.driver.find_element(*self.nav_right_locator)
        # 点击头像#
        nav_right.find_element(*self.dropdown_open_locator).click()
        sleep(2)
        # 点击系统设置#
        self.driver.find_element(*self.system_settings_locator).click()
        sleep(2)
    def click_business(self):
        #点击商机#
        self.find_element(self.business_locator).click()
    def click_knowledge(self):
        """点击知识"""
        self.click(self.click_knowledge_locator)
    def click_log(self):
        """点击日志"""
        self.click(self.click_log_locator)
    def click_in_site_message(self):
        """点击站内信"""
        self.click(self.click_in_site_message_locator)
